home *** CD-ROM | disk | FTP | other *** search
-
- {*******************************************************}
- { }
- { Delphi Visual Component Library }
- { DataSet Interface Unit }
- { }
- { Copyright (c) 1997 Borland International }
- { }
- {*******************************************************}
-
- unit DSIntf;
-
- {$MINENUMSIZE 4}
-
- interface
-
- uses BDE, Windows;
-
- const
- dsRecOrg = $0001; // Original record (was changed)
- dsRecDeleted = $0002;
- dsRecNew = $0004;
- dsRecModified = $0008; // Record was changed
- // dsRecent = $0010; // Most recent version of a changed record (visible)
- dsUnused = $0020; // Not used anymore
-
- dsISNOTVISIBLE = dsRecDeleted or dsRecOrg or dsUnused;
- dsISVISIBLE = not (dsRecDeleted or dsRecOrg or dsUnused);
- // dsCHANGED = dsRecDeleted or dsRecNew or dsRecModified or dsRecOrg;
-
-
- // Additional fieldtypes
- fldINT8 = $1001;
- fldUINT8 = $1002;
- fldBOOL8 = $1003;
- fldBOOL16 = fldBOOL;
- fldBOOL32 = $1004;
- fldINT64 = $1005;
- fldUINT64 = $1006;
- fldUNICODE = $1007;
-
- MAXFIELDLEN = 256;
- MAXKEYFIELDS = 16;
-
-
- type
-
- DSAttr = Byte;
- pDSAttr = ^DSAttr;
-
- DSKEY = packed array[0..DBIMAXFLDSINKEY-1] of Integer;
- DSKEYBOOL = packed array[0..DBIMAXFLDSINKEY-1] of Bool;
-
- hDSFilter = Pointer;
- phDSFilter = ^hDSFilter;
-
- hDSAggregate = Integer;
- phDSAggregate = ^hDSAggregate;
-
- DSRECNUM = Longint; // 1-based record number. 0 and negative might have special meaning
- DSSEQNUM = Integer; // 1-base sequence number of record. 0 means undefined.
-
- type
- DSShareMode = ( // Database/Table Share type
- dsOPENSHARED, // Open shared (Default)
- dsOPENEXCL // Open exclusive
- );
-
- DSOpenMode = ( // Database/Table Access type
- dsREADWRITE, // Read + Write (Default)
- dsREADONLY // Read only
- );
-
- BOOKMRK = Pointer;
- pBOOKMRK = ^BOOKMRK;
-
- pDSBOOKMRK = ^DSBOOKMRK;
- DSBOOKMRK = packed record
- iPos : Integer; // Position in given order
- iState : Integer; // State of cursor
- iRecNo : Integer; // Record number
- iSeqNo : Integer; // Version number of order
- iOrderID : Integer; // Defines Order
- end;
-
- const
- BOOKMARKSIZE = sizeof(DSBOOKMRK);
-
- type
- DSProp = (
- dspropLOGCHANGES, // rw BOOL(TRUE), logs changes for undo/delta
- dspropREADONLY, // rw BOOL(TRUE), cannot update dataset (is NOT stored with dataset,-use AddOptParameter)
- dspropNOOFCHANGES, // r UINT32, number of (compressed) changes (m/i/d)
- dspropCONSTRAINTS_DISABLED, // rw BOOL(TRUE), constraints are disabled (insert/modify/delete)
- dspropDSISPARTIAL // r BOOL(TRUE), Dataset is not yet complete (async. mode)
- );
-
- CURProp = (
- curpropCONSTRAINT_ERROR_MESSAGE // r pCHAR (returns POINTER to string, not string itself)
- );
-
- const
- fldstUNKNOWN = 255;
-
- // Misc. alchemy error-messages
- const
- ERRCAT_ALC = $40;
- ERRBASE_ALC = $4000;
-
- ERRCODE_DELTAISEMPTY = 1; // Delta is empty.
- ERRCODE_NOTHINGTOUNDO = 2; // Nothing to undo
-
- DBIERR_DELTAISEMPTY = ERRBASE_ALC + ERRCODE_DELTAISEMPTY;
- DBIERR_NOTHINGTOUNDO = ERRBASE_ALC + ERRCODE_NOTHINGTOUNDO;
- { !!! Add missing ones here from AlcTypes. }
-
- BLANK_NULL = 1; // 'real' NULL
- BLANK_NOTCHANGED = 2; // Not changed , compared to original value
-
- type
-
- { Field Descriptor }
-
- pDSFLDDesc = ^DSFLDDesc;
- DSFLDDesc = packed record
- szName : DBINAME; // Field name
- iFldType : Integer; // Field type
- iFldSubType : Integer; // Field subtype (if applicable)
- iUnits1 : Integer; // Number of Chars, precision etc
- iUnits2 : Integer; // Decimal places etc.
- iFldLen : Integer; // Length in bytes (computed)
- iFldOffsInRec : Integer; // Offset to field in record buffer
- iNullOffsInRec : Integer; // Offset to null flag (1byte) in record buffer
- bHidden : Bool; // Field is a hidden field
- bCalculated : Bool; //
- bReadOnly : Bool; // Field is not updatetable
- iOptParameters : Integer; // Number of optional parameters for field
- end;
-
- { Index descriptor }
-
- pDSIDXDesc = ^DSIDXDesc;
- DSIDXDesc = packed record
- szName : DBINAME; // IndexName
- iFields : Integer; // Number of fields in order (0 -> base order)
- iKeyFields: DSKEY; // FieldNumbers
- iKeyLen : Integer; // Total length of key (computed)
- bUnique : Bool;
- bDescending : DSKEYBOOL; // TRUE ->Descending
- bCaseInsensitive : DSKEYBOOL;
- end;
-
- { Cursor Properties }
-
- pDSProps = ^DSProps;
- DSProps = packed record
- szName : DBIPATH; // Name, if any
- iFields : Integer; // Number of columns
- iRecBufSize : Integer; // Size of record buffer
- iBookMarkSize : Integer; // Size of bookmark
- bReadOnly : Bool; // Dataset is not updateable
- iIndexes : Integer; // Number of indexes on dataset
- iOptParams : Integer; // Number of optional parameters
- bDelta : Bool; // This is a delta dataset
- iLCID : Integer; // Language used
- iUnused : packed array[0..7] of Integer; // Reserved
- end;
-
- type
- // Change Notification callback
- pfCHANGECallBack = procedure( // Call-back funtion pntr type
- iClientData : Integer // Client callback data
- ); stdcall;
-
- // Filter callback
- type
- pfDSFilter = function(
- iClientData : Integer;
- pRecBuf : PChar
- ): Bool; stdcall;
-
- // Calculated field callback
- type
- pfDSCalcField = function(
- iClientData : Integer;
- pRecBuf : PChar // Current record-buffer
- ): DBIResult; stdcall;
-
- // Resolver & Reconcile callback return values
- const
- dscbrSKIP = 1; { Skip this operation (resolver : report error). }
- dscbrABORT = 2; { Abort the callback session (reconcile or resolve). }
- { (resolver : undo all changes). }
- dscbrMERGE = 3; { Merge the changes (resolver : 'simple' merge) }
- { (reconcile : update original. Keep change). }
- { Resolving only }
- dscbrAPPLY = 4; { Overwrite the current record with new values. }
- dscbrIGNORE = 5; { Ignore the update request. Don't report error. }
-
- { Reconcile only }
- dscbrCORRECT = 4; { Overwrite change with new values. }
- dscbrCANCEL = 5; { Cancel change (remove from delta). }
- dscbrREFRESH = 6; { Update original record. Cancel change. }
-
- type
- dsCBRType = Integer;
- pdsCBRType = ^dsCBRType;
-
- //
- type
- DSErrorCategory = type Integer; // Resolver Error Category
- const
- dsErrCategoryOTHER = $0001;
- dsErrCategoryDATALOSS = $0002;
- dsErrCategoryNOTFOUND = $2200;
- dsErrCategoryINTEGRITY = $2600;
- dsErrCategoryLOCKCONFLICT = $2800;
- dsErrCategorySECURITY = $2900;
-
- // Reconcile-callback
- type
- pfDSReconcile = function(
- iClientData : Integer; //
- iRslt : Integer; // Result of previous callback. If set, the previuos parameters are repeated.
- iAction : DSAttr; // Update request Insert/Modify/Delete
- iResponse : dsCBRType; // Resolver response (used only by Reconcile).
- iErrCode : Integer; // Native error-code, (BDE or ..)
- pErrMessage : PChar; // Native errormessage, if any (otherwise NULL)
- pErrContext : PChar; // 1-level error context, if any (otherwise NULL)
- pRecUpd : PByte; // Record that failed update
- pRecOrg : PByte; // Original record, if any
- pRecConflict : PByte // Conflicting error, if any
- ): dsCBRType; stdcall;
-
-
- type
-
- { IDSBase }
-
- IDSBase = interface(IUnknown)
- ['{9E8D2F82-591C-11D0-BF52-0020AF32BD64}']
-
- function Create( // Create empty dataset
- iFields : Integer;
- pFldDes : pDSFLDDesc;
- pszName : PChar
- ): DBIResult; stdcall;
-
- function AddField(
- pFldDes : pDSFLDDesc
- ): DBIResult; stdcall;
-
- function AppendData( // Appends data packet to dataset.
- pPacket : PVarArray; // Data packet
- bEof : Bool // If True, this is last packet
- ): DBIResult; stdcall;
-
- function GetOptParameter( // Returns optional parameter (unknown to dataset)
- iNo : Integer; // Number 1..iOptAttr
- iFldNo : Integer; // 0 if not field attribute
- ppName : Pointer; // returns ptr to name
- var piType : Integer; // returns type
- var piLen : Integer; // returns length
- var ppValue : PChar // returns ptr to value
- ): DBIResult; stdcall;
-
- function AddOptParameter( // Adds optional parameter to dataset
- iFldNo : Integer; // 0 if not field attribute
- pszAttr : PChar; // ptr to name
- iType : Integer; // type
- iLen : Integer; // length
- pValue : Pointer // ptr to value
- ): DBIResult; stdcall;
-
- function GetProps(
- var p1 : DSProps
- ): DBIResult; stdcall;
-
- function GetFieldDescs(
- p1 : pDSFLDDesc
- ): DBIResult; stdcall;
-
- function GetIndexDescs(
- p1: PDSIDXDesc
- ): DBIResult; stdcall;
-
- function GetDelta( // Extract delta from ds, as delta
- out DsDelta: IDSBase // Returns dataset (must be cast to pDSBASE)
- ): DBIResult; stdcall;
-
- function StreamDS( // Create data packet from the dataset
- out ppPacket: PVarArray // Return data packet
- ): DBIResult; stdcall;
-
- function AcceptChanges: DBIResult; stdcall; // Accept all current changes (cannot be undone).
-
- function CreateIndex( // Create, and add an index
- const IdxDesc : DSIDXDesc
- ): DBIResult; stdcall;
-
- function RemoveIndex( // Remove index of given name
- pszName : PChar
- ): DBIResult; stdcall;
-
- function GetErrorString(
- iErrCode : DBIResult;
- pString : PChar
- ): DBIResult; stdcall;
-
- function GetProp( // Get property
- eProp : DSProp;
- var iPropValue : Integer
- ): DBIResult; stdcall;
-
- function SetProp( // Set property
- eProp : DSProp;
- iPropValue : Integer
- ): DBIResult; stdcall;
-
- function SetFieldCalculation( // Register fieldcalculation on this field
- iClientData : Integer;
- pfCalc : pfDSCalcField // Callback function, NULL to remove
- ): DBIResult; stdcall;
-
- function Reconcile(
- pDeltaPacket : PVarArray; // Delta data packet
- pErrorPacket : PVarArray; // NULL if all changes accepted
- iClientData : Integer;
- pfReconcile : pfDSReconcile // Callback-fn (called for each error)
- ): DBIResult; stdcall;
-
- function AddAggregate(
- pcanExpr : Pointer;
- iLen : Integer; // Length of canexpr
- pDsFldDesc : pDSFLDDesc; // returns field-descriptor for aggregate
- phAggregate : phDSAggregate // returns aggregate handle
- ): DBIResult; stdcall;
-
- function DropAggregate(
- hAggregate : hDSAggregate
- ): DBIResult; stdcall;
-
- function GetAggregateValue(
- hAggregate : hDSAggregate;
- pValue : PByte // returns aggregate value
- ): DBIResult; stdcall;
-
- function Refresh(
- pNewPacket : PVarArray; // New updated packet
- iClientData : Integer;
- pfReconcile : pfDSReconcile // Callback for resolving conflicts
- ): DBIResult; stdcall;
-
- end;
-
- { IDSCursor }
-
- IDSCursor = interface(IUnknown)
- ['{9E8D2F84-591C-11D0-BF52-0020AF32BD64}']
-
- function InitCursor( // Associate Cursor with a DataSet
- DataSet: IDSBase
- ): DBIResult; stdcall;
-
- function CloneCursor( // Clone cursor from cursor
- Cursor: IDSCursor
- ): DBIResult; stdcall;
-
- function GetCursorProps( // Get cursor properties
- var p1: DSProps
- ): DBIResult; stdcall;
-
- function GetIndexDescs(
- bCurrentOnly : Bool; // Only return 'current' indexdesc, otherwise all
- var IdxDesc : DSIDXDesc
- ): DBIResult; stdcall;
-
- function GetFieldDescs( // Get field descriptors
- p1 : pDSFLDDesc
- ): DBIResult; stdcall;
-
- function GetCurrentRecord( // Return record at current cursorposition
- pRecBuf : Pointer
- ): DBIResult; stdcall;
-
- function GetRecordBlock( // Return block of records
- piRecs : PULONG;
- pRecBuf : Pointer
- ): DBIResult; stdcall;
-
- function GetCurrentBookMark( // Get bookmark for current position
- pBookMark : Pointer
- ): DBIResult; stdcall;
-
- function GetSequenceNumber( // Get Sequence number of current position
- var iSeq : Integer
- ): DBIResult; stdcall;
-
- function GetRecordAttribute( // Get record attribute of current position
- var Attr : DSAttr
- ): DBIResult; stdcall;
-
- function GetRecordCount( // Number of records in active view
- var iRecs : Integer
- ): DBIResult; stdcall;
-
- { Navigation }
-
- function MoveToBOF: DBIResult; stdcall; // Set to beginning of table (BOF)
- function MoveToEOF: DBIResult; stdcall; // Set to end of table (EOF)
- function MoveRelative(i: Integer): DBIResult; stdcall;
- function MoveToSeqNo(i: Integer): DBIResult; stdcall;
- function MoveToBookMark(
- pBookMark: Pointer): DBIResult; stdcall;
- function MoveToKey(
- SearchCond : DBISearchCond;
- iFields : Integer;
- iPartLen : Integer;
- pRecBuf : Pointer): DBIResult; stdcall;
-
-
- function CompareBookMarks( // Compare two bookmark (positions) -1, 0, 1
- pBookMark1 : Pointer;
- pBookMark2 : Pointer;
- var iCmp : Integer
- ): DBIResult; stdcall;
-
- function ExtractKey( // Extract key from record
- pRecBuf : Pointer;
- pKeyBuf : Pointer
- ): DBIResult; stdcall;
-
- function GetRecordForKey( // Return (first) record with given key
- iFields : Integer;
- iPartLen : Cardinal;
- pKey : Pointer;
- pRecBuf : Pointer
- ): DBIResult; stdcall;
-
- function GetField( // Extract field value from record buffer
- pRecBuf : Pointer;
- iFieldNo : Integer;
- pFldBuf : Pointer;
- var bBlank : Bool // Returns TRUE/FALSE if blank
- ): DBIResult; stdcall;
-
- function PutField( // Put field value into record buffer
- pRecBuf : Pointer;
- iFieldNo : Integer;
- pFldBuf : Pointer // If NULL, adds a blank value
- ): DBIResult; stdcall;
-
- { Blob functions }
-
- function GetBlobLen( // Return length of blob
- pRecBuf : Pointer;
- iFieldNo : Integer;
- var iLength : Integer
- ): DBIResult; stdcall;
-
- function GetBlob( // Return blob
- pRecBuf : Pointer;
- iFieldNo : Integer;
- iOffSet : Integer; // Starting position
- pBuf : Pointer;
- var iLength : Integer // No of bytes to be read/ returns number read
- ): DBIResult; stdcall;
-
- function PutBlob(
- pRecBuf : Pointer;
- iFieldNo : Integer;
- iOffSet : Integer; // Starting position
- pBuf : Pointer;
- iLength : Integer
- ): DBIResult; stdcall;
-
- { Update functions }
-
- function InitRecord( // Initialize record buffer (for insertion)
- pRecBuf : Pointer
- ): DBIResult; stdcall;
-
- function DeleteRecord: DBIResult; stdcall; // Delete current record
-
- function ModifyRecord( // Modify current record
- pRecBuf : Pointer
- ): DBIResult; stdcall;
-
- function InsertRecord( // Insert new record
- pRecBuf : Pointer
- ): DBIResult; stdcall;
-
- function UndoLastChange( // Undo last update
- bFollowChange : Bool
- ): DBIResult; stdcall;
-
- function AddFilter( // Add a canexpr-filter to this cursor
- pcanExpr : Pointer; // Can expr
- iLen : Integer; // Length of canexpr
- var hFilter : hDSFilter
- ): DBIResult; stdcall;
-
- function DropFilter( // Drop a filter
- hFilter : hDSFilter
- ): DBIResult; stdcall;
-
- function SetRange( // Set a range on a cursor
- iFields : Integer;
- pKey1 : Pointer;
- bKey1Incl : Bool;
- pKey2 : Pointer;
- bKey2Incl : Bool
- ): DBIResult; stdcall;
-
- function DropRange: DBIResult; stdcall; // Remove current range
-
- function SortOnFields( // Sort on fields
- iFields : Integer;
- piFields : PInteger; // NULL -> all fields
- pDescending: PBool; // NULL -> all ascending
- pCaseInsensitive: PBool // NULL -> all case-sensitive
- ): DBIResult; stdcall;
-
- function UseIndexOrder( // Switch to index order
- pszName : PChar
- ): DBIResult; stdcall;
-
- function SetNotifyCallBack( // Called when posting changes to dataset
- iClientData : Integer;
- pfCallBack : pfCHANGECallBack // Call back fn being registered
- ): DBIResult; stdcall;
-
- function AddFilterCallBack( // Add a canexpr-filter to this cursor
- iClientData : Integer; // Client supplied data
- pfFilter : pfDSFilter; // ptr to filter function
- var hFilter : hDSFilter
- ): DBIResult; stdcall;
-
- function VerifyField( // Verify if field value is valid
- iFieldNo : Integer;
- pFldBuf : Pointer
- ): DBIResult; stdcall;
-
- function GetProp( // Get property
- eProp : CURProp;
- var iPropValue : Integer
- ): DBIResult; stdcall;
-
- function RevertRecord: DBIResult; stdcall; // Restore current record
-
- end;
-
- const
- CLSID_DSBase: TGUID = '{9E8D2F81-591C-11D0-BF52-0020AF32BD64}';
- CLSID_DSCursor: TGUID = '{9E8D2F83-591C-11D0-BF52-0020AF32BD64}';
-
- implementation
-
-
- end.
-